
/**
 * ...
 * @author HTML5
 */

function Arrow()
{
	tomahawk_ns.Sprite.apply(this);
	this.mouseEnabled = true;
	this._shape = this._drawShape();
	this._field = this._drawTextField();
	this.addChild(this._shape);
	this.addChild(this._field);
	this.width = 100;
	this.height= 54;
	
	this._field.name = "arrow_field";
}

Tomahawk.registerClass( Arrow, "Arrow" );
Tomahawk.extend( "Arrow", "Sprite" );

Arrow.prototype._field = null;
Arrow.prototype._shape = null;
Arrow.prototype._lastValue = 0;
Arrow._currentArrow = null;

Arrow.prototype.getValue = function()
{
	return parseInt(this._field._text);
};

Arrow.prototype.draw = function(context)
{
	var value = this.getValue();
	
	if( value != this._lastValue  && !isNaN(value) )
	{
		this._lastValue = value;
		this.dispatchEvent( new tomahawk_ns.Event("change",true,true) );
	}
	
	tomahawk_ns.Sprite.prototype.draw.apply(this,[context]);
};

Arrow.prototype.setValue = function(value)
{
	this._field.setText(value+"");
};

Arrow.prototype.select = function(value)
{
	this._field.setFocus(value);
	this._field.setCurrentIndex(0);
};

Arrow.prototype._drawTextField = function()
{
	var field = new tomahawk_ns.InputTextField();
	var format = new tomahawk_ns.TextFormat();
	format.size = 30;
	format.textColor = "black";
	
	field.cursorColor = "black";
	field.mouseEnabled = true;
	field.defaultTextFormat = format;
	field.width = 75;
	field.height = 35;
	field.y = 10;
	field.x = 20;
	field.background = true;
	field.setTextAlign( tomahawk_ns.TextField.ALIGN_CENTER);
	field.backgroundColor = "white";
	field.setText("0");
	
	return field;
};

Arrow.prototype._drawShape = function()
{
	var shape = new tomahawk_ns.Shape();
	shape.clear();
	shape.width = 85;
	shape.height = 54;
	shape.mouseEnabled = true;
	shape.beginPath();
	shape.fillStyle("black");
	shape.moveTo(0,27);
	shape.lineTo(15,0);
	shape.lineTo(15,54);
	shape.lineTo(0,27);
	shape.fill();
	shape.beginPath();
	shape.fillRect(14,0,85,54);
	shape.fill();
	
	shape.beginPath();
	shape.moveTo(0,27);
	shape.lineTo(-360, 27);
	shape.stroke();
	
	return shape;
};

